package com.base.components.database.dao.base;

import org.hibernate.transform.AliasedTupleSubsetResultTransformer;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * AliasToEntityLinkedMapResultTransformer
 *
 * @author <a href="drakelee1221@gmail.com">LiGeng</a>
 * @version v1.0.0
 * @date 2019-01-18 10:39
 */
public class AliasToEntityLinkedMapResultTransformer extends AliasedTupleSubsetResultTransformer {
  public static final AliasToEntityLinkedMapResultTransformer INSTANCE = new AliasToEntityLinkedMapResultTransformer();

  private AliasToEntityLinkedMapResultTransformer(){}

  @Override
  public Object transformTuple(Object[] tuple, String[] aliases) {
    Map result = new LinkedHashMap(tuple.length);
    for(int i = 0; i < tuple.length; ++i) {
      String alias = aliases[i];
      if(alias != null) {
        result.put(alias, tuple[i]);
      }
    }
    return result;
  }

  @Override
  public boolean isTransformedValueATupleElement(String[] strings, int i) {
    return false;
  }
}
